/**
 * Copyright @ 2010-2015 Hex company All rights reserved
 * 系统名称：DCP
 * 模块名称：
 *
 * @version版本信息：V1.0
 * @author:jiewang
 */
package com.hex.ds.hdrs.common.utils;

import cn.hutool.core.date.DateTime;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * @Package: com.hex.ds.hdrs.common.utils
 * @ClassName DateUtil
 * @Description:
 * @Author: 时间日期工具类<gc.zuo>
 * @Date 2021/7/8 15:13
 * @Version v1.0
 **/
public class HdrsDateUtil {
    public static final String YYYYMMDD = "yyyyMMdd";
    public static final String YYYY_MM_DDHHMISS = "yyyy-MM-dd HH:mm:ss";
    public static final String YYYY_MM_DDHHMISSSSS = "yyyy-MM-dd HH:mm:ss SSS";
    public static final String YYYY_MM_DD = "yyyy-MM-dd";
    protected static final String[] WEEK_OF_DAYS = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

    /**
     * @Method: getFormat <br>
     * @Param: [] <br>
     * @Return: java.text.SimpleDateFormat <br>
     * @Description：获取SimpleDateFormat对象<br>
     * @Author： gc.zuo<br>
     * @Date： 2021/7/8 11:40 <br>
     * @Version： V1.0<br>
     */
    public static SimpleDateFormat getFormat() {
        SimpleDateFormat format = new SimpleDateFormat(YYYYMMDD);
        return format;
    }

    /**
     * @Method: getCalendar <br>
     * @Param: [] <br>
     * @Return: java.util.Calendar <br>
     * @Description：获取calendar对象<br>
     * @Author： gc.zuo<br>
     * @Date： 2021/7/8 11:41 <br>
     * @Version： V1.0<br>
     */
    public static Calendar getCalendar() {
        Calendar calendar = Calendar.getInstance();
        return calendar;
    }

    /**
     * 获取当前时间  yyyy-MM-dd HH:mm:ss
     *
     * @return
     */
    public static String getCurTs() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS));
    }

    /**
     * 获取当前时间  yyyy-MM-dd HH:mm:ss SSS
     *
     * @return
     */
    public static String getCurTsMs() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISSSSS));
    }

    /**
     * 获取下一日期   yyyy-MM-dd
     *
     * @param date
     * @return
     */
    public static String getNextDay(String date) {
        String[] dateArr = date.split("-");
        LocalDate localDate = LocalDate.of(Integer.parseInt(dateArr[0])
                , Integer.parseInt(dateArr[1]), Integer.parseInt(dateArr[2]));
        localDate = localDate.minusDays(-1);
        return localDate.toString();
    }

    /**
     * 获取当前时间  yyyy-MM-dd
     *
     * @return
     */
    public static String getCurDate() {
        return LocalDate.now().toString();
    }

    /**
     * 获取当前小时
     *
     * @return
     */
    public static int getHour() {
        return LocalDateTime.now().getHour();
    }

    /**
     * 获取推前时间
     *
     * @param type
     * @param time
     * @return
     */
    public static String plusHours(String type, int diff, String time) {
        LocalDateTime date = LocalDateTime.now();
        LocalDateTime localDateTime = null;
        if ("0" == type) {
            //分钟
            localDateTime = date.minusMinutes(diff);
        } else if ("1" == type) {
            localDateTime = date.minusHours(diff);

        }
        if (null != localDateTime) {
            return localDateTime.format(DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS));
        } else {
            return null;
        }
    }

    /**
     * 获取当日8位日期
     *
     * @return String
     */
    public static String getCurrentDate() {
        return HdrsDateUtil.format(new Date(), HdrsDateUtil.YYYYMMDD);
    }

    /**
     * 获取昨日8位日期
     *
     * @return String
     */
    public static String getYesterDate() {
        Calendar cal = getCalendar();
        cal.add(Calendar.DATE, -1);
        return HdrsDateUtil.format(cal.getTime(), HdrsDateUtil.YYYYMMDD);
    }

    /**
     * 获取当日日期时分秒 yyyy-MM-dd HH:mm:ss
     *
     * @return String
     */
    public static String getCurrentTime() {
        return HdrsDateUtil.format(new Date(), HdrsDateUtil.YYYY_MM_DDHHMISS);
    }

    /**
     * 日期格式转换
     *
     * @param date
     * @param patten
     * @return String
     */
    public static String format(Date date, String patten) {
        java.text.DateFormat format2 = new java.text.SimpleDateFormat(patten);

        return format2.format(date);
    }

    /**
     * 日期对象转换
     *
     * @param dateStr
     * @param patten
     * @return String
     */
    public static Date parser(String dateStr, String patten) {
        try {
            java.text.DateFormat format2 = new java.text.SimpleDateFormat(patten);
            Date date = format2.parse(dateStr);
            return date;
        } catch (Exception e) {

        }
        return null;
    }

    /**
     * string 转 long
     *
     * @param dateStr
     * @param patten
     * @return
     */
    public static long strToLong(String dateStr, String patten) {
        Date date = parser(dateStr, patten);
        return getMillis(date);
    }

    /**
     * 获取当日日期没有时分秒对象
     *
     * @return String
     */
    public static Date getCurrentDateNoTime() {
        String datestr = getNormalDate(new Date());
        return HdrsDateUtil.getDate(datestr);
    }

    /**
     * 日期转换成标准的YYYY_MM_DD
     *
     * @param date
     * @return String
     */
    public static String getNormalDate(Date date) {
        return HdrsDateUtil.format(date, HdrsDateUtil.YYYY_MM_DD);
    }

    /**
     * 日期转换成标准的YYYYMMDD
     *
     * @param date
     * @return String
     */
    public static String getNormalYYYYMMDDDate(Date date) {
        return HdrsDateUtil.format(date, HdrsDateUtil.YYYYMMDD);
    }
//	/**
//	 * 毫秒转换成日期
//	 * @param time
//	 * @return Date
//	 * */
//	public static Date getDate(int time){
//		//SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
//        Date dt = HSSFDateUtil.getJavaDate(time);//获取成DATE类型
//          return dt ;
//	}

    /**
     * 格式化数据库日期
     *
     * @param date
     * @return String
     */
    public static String getFormate(java.sql.Date date) {
        if (date != null) {

            //DateUtil.
            return getNormalYYYYMMDDDate(date);
        }
        return null;
    }

    /**
     * 日期字符串转换成指定格式的日期
     *
     * @param val
     * @param patten
     * @return String
     */
    public static String getYearMonth(String val, String patten) {
        if (!StringUtils.isEmpty(val)) {
            try {
                String[] dateFormats = new String[]{
                        "yyyy-MM",
                        "yyyy年MM月",
                        "yyyy/MM",
                        "yyyyMM",
                        "yyyy.MM",
                        "yyyy年M月"

                };
                Date date = DateUtils.parseDate(val, dateFormats);

                String val2 = format(date, patten);
                return val2;
            } catch (Exception e) {

            }

        }
        return null;
    }

    /**
     * 判断日期是否是合法的年月格式
     *
     * @param val
     * @return boolean
     */
    public static boolean isYearMonth(String val) {
        if (val.length() >= 6) {
            String newVal = val;
            newVal = newVal.replaceAll("-", "");
            newVal = newVal.replaceAll("年", "");
            newVal = newVal.replaceAll("月", "");
            //newVal = newVal.replaceAll("日", "");
            newVal = newVal.replaceAll("/", "");
            newVal = newVal.replaceAll("\\.", "");
            if (newVal.length() > 6) {
                return false;
            }
            if (NumberUtils.isNumber(newVal)) {
                try {
                    String[] dateFormats = new String[]{
                            "yyyy-MM",
                            "yyyy年MM月",
                            "yyyy/MM",
                            "yyyyMM",
                            "yyyy.MM",
                            "yyyy年M月"

                    };
                    Date date = DateUtils.parseDate(val, dateFormats);

                    String val2 = format(date, "yyyyMM");
                    String val3 = format(date, "yyyyM");
                    if (!newVal.equals(val2) && !newVal.equals(val3)) {
                        return false;
                    }

                    return true;
                } catch (Exception e) {

                }

            }
        }
        return false;
    }

    /**
     * 日期字符串转换成日期对象
     *
     * @param dataVal
     * @return Date
     */
    public static Date getDate(String dataVal) {
        String str = dataVal;

        if (str != null) {
            String newVal = dataVal;
            if (dataVal.length() > 8) {
                newVal = newVal.replaceAll("-", "");
                newVal = newVal.replaceAll("年", "");
                newVal = newVal.replaceAll("月", "");
                newVal = newVal.replaceAll("日", "");
                newVal = newVal.replaceAll("/", "");
                newVal = newVal.replaceAll("\\.", "");

            }
            try {
                String[] dateFormats = new String[]{
                        "yyyy-MM-dd",
                        "yyyy年MM月dd日",
                        "yyyy/MM/dd",
                        "yyyyMMdd",
                        "yyyy.MM.dd"
                };
                Date date = DateUtils.parseDate(str, dateFormats);

                String val = format(date, "yyyyMMdd");
                if (!newVal.equals(val)) {
                    return null;
                }

                return date;
            } catch (Exception e) {

            }
        }
        return null;
    }

    /**
     * 判断当前日期是否在有效日期内
     *
     * @param beginDate
     * @param endDate
     * @return boolean
     */
    public static boolean isValidDate(String beginDate, String endDate) {
        Date cDate = getCurrentDateNoTime();
        Date bDate = HdrsDateUtil.getDate(beginDate);
        Date eDate = HdrsDateUtil.getDate(endDate);
        if (null != cDate) {
            if (cDate.after(bDate) && cDate.before(eDate)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    public static String getCurrentTime18() {
        String ss = HdrsDateUtil.format(new Date(), HdrsDateUtil.YYYY_MM_DDHHMISSSSS);
        return ss.replaceAll(":", "").replaceAll("_", "");
    }

    public static String convertMsToSeconds(long ms) {
        double seconds = ms / 1000.0000;
        return String.valueOf(seconds);
    }

    public static String getDaysAgo(int n) {
        Calendar calendar1 = Calendar.getInstance();
        SimpleDateFormat sdf1 = new SimpleDateFormat(YYYY_MM_DD);
        calendar1.add(Calendar.DATE, n);
        return sdf1.format(calendar1.getTime());
    }

	/*public static void main(String[] args) {
//		DateUtil.getNormalDate(DateUtil
//				.getDate("20151301"));
		//Date date = DateUtil.parser("2020-10-27T05:00:00.000Z","yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		//String time = DateUtil.getCurrentTime() ;
		System.out.println(LocalDateTime.now().toString());
	}*/

    /**
     * 获取一年天数
     *
     * @param year
     * @return
     */
    public static int getDays(int year) {
        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
            return 366;
        } else {
            return 365;
        }
    }

    /**
     * 一年中第几天
     *
     * @param dateStr
     * @return
     */
    public static int getDayOfYear(String dateStr) {
        Date date = getFormat().parse(dateStr, new ParsePosition(0));
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_YEAR);
    }

    /**
     * 一周中第几天
     *
     * @param dateStr
     * @return
     */
    public static int getDayOfWeek(String dateStr) {
        Date date = getFormat().parse(dateStr, new ParsePosition(0));
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_WEEK) - 1;
    }

    public static String getDayOfWeekCn(String dateStr) {
        Date date = getFormat().parse(dateStr, new ParsePosition(0));
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return WEEK_OF_DAYS[week];
    }

    /**
     * 获取推前时间
     *
     * @param type 0:分钟 1：小时
     * @param time
     * @return
     */
    public static String getAheadTime(String type, int diff, String time) {

        DateTimeFormatter df = DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS);
        LocalDateTime date = LocalDateTime.parse(time, df);
        LocalDateTime localDateTime = null;
        if ("0".equals(type)) {
            // 分钟
            localDateTime = date.minusMinutes(diff);
        } else if ("1".equals(type)) {
            // 小时
            localDateTime = date.minusHours(diff);
        } else if ("2".equals(type)) {
            // 月
            localDateTime = date.minusMonths(diff);
        }
        if (null != localDateTime) {
            return localDateTime.format(DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS));
        } else {
            return null;
        }
    }

    public static Date addDay(int amount) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, amount);
        return cal.getTime();
    }

    /**
     * 获取推后时间
     *
     * @param type type 0:分钟 1：小时
     * @param time
     * @return
     */

    public static String getPlusTime(String type, int diff, String time) {

        DateTimeFormatter df = DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS);
        LocalDateTime date = LocalDateTime.parse(time, df);
        LocalDateTime localDateTime = null;
        if ("0" == type) {
            // 分钟
            localDateTime = date.plusMinutes(diff);
        } else if ("1" == type) {
            localDateTime = date.plusHours(diff);

        }
        if (null != localDateTime) {
            return localDateTime.format(DateTimeFormatter.ofPattern(YYYY_MM_DDHHMISS));
        } else {
            return null;
        }
    }

    /**
     * 功能描述：返回月
     *
     * @param date Date 日期
     * @return 返回月份
     */
    public static int getMonth(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.MONTH) + 1;
    }

    /**
     * 功能描述：返回日
     *
     * @param date Date 日期
     * @return 返回日份
     */
    public static int getDay(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.DAY_OF_MONTH);
    }

    /**
     * 功能描述：返回小
     *
     * @param date 日期
     * @return 返回小时
     */
    public static int getHour(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 功能描述：返回分
     *
     * @param date 日期
     * @return 返回分钟
     */
    public static int getMinute(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.MINUTE);
    }

    /**
     * 返回秒钟
     *
     * @param date Date 日期
     * @return 返回秒钟
     */
    public static int getSecond(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.get(Calendar.SECOND);
    }

    /**
     * 功能描述：返回毫
     *
     * @param date 日期
     * @return 返回毫
     */
    public static long getMillis(Date date) {
        Calendar calendar = getCalendar();
        calendar.setTime(date);
        return calendar.getTimeInMillis();
    }

    public static String msToDateStr(long ms) {
        Date date = new Date(ms);
        return format(date, YYYY_MM_DDHHMISS);
    }

    public static List<Date> getBetweenDates(Date start, Date end) {
        List<Date> result = new ArrayList<Date>();
        Calendar tempStart = Calendar.getInstance();
        tempStart.setTime(start);
        tempStart.add(Calendar.DAY_OF_YEAR, 1);

        Calendar tempEnd = Calendar.getInstance();
        tempEnd.setTime(end);
        while (tempStart.before(tempEnd)) {
            result.add(tempStart.getTime());
            tempStart.add(Calendar.DAY_OF_YEAR, 1);
        }
        return result;
    }

    public static List<String> getBetweenDates(String startTime, String endTime) {
        // 返回的日期集合
        List<String> days = new ArrayList<String>();
        Date start = parser(startTime, "yyyy-MM-dd");
        Date end = parser(endTime, "yyyy-MM-dd");

        Calendar tempStart = Calendar.getInstance();
        tempStart.setTime(start);

        Calendar tempEnd = Calendar.getInstance();
        tempEnd.setTime(end);
        tempEnd.add(Calendar.DATE, +1);// 日期加1(包含结束)
        while (tempStart.before(tempEnd)) {
            days.add(format(tempStart.getTime(), "yyyy-MM-dd"));
            tempStart.add(Calendar.DAY_OF_YEAR, 1);
        }
        return days;
    }

    /**
     * 减对应时间后的日期
     *
     * @param amount 加减的时间(毫秒)
     * @return 加减对应时间后的日期
     */
    public static String subtractTime(int amount) {
        try {
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.format(date.getTime() - amount);
        } catch (Exception e) {

        }
        return null;
    }

    /**
     * 判断日期是周几
     *
     * @param pTime
     * @return
     * @throws Throwable
     */
    public static String dayForWeek(String pTime) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date tmpDate = format.parse(pTime);
        Calendar cal = Calendar.getInstance();
        String[] weekDays = {"7", "1", "2", "3", "4", "5", "6"};
        try {
            cal.setTime(tmpDate);
        } catch (Exception e) {

        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0) {
            w = 0;
        }
        return weekDays[w];
    }

    /**
     * 判断某个时间点是否等于设定的时间点
     *
     * @param time    多个时间点，以英文逗号分隔
     * @param nowTime
     * @return
     */
    public static boolean checkEqualTimePoints(String time, String nowTime) {
        if (org.apache.commons.lang3.StringUtils.isBlank(time)) {
            return false;
        }
        String[] times = time.split(",");
        if (times == null || times.length < 1) {
            return false;
        }
        List<String> timeList = Arrays.asList(times);
        if (timeList.contains(nowTime)) {
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        long ms = getMillis(new Date());
        System.out.println(ms);
        String date = msToDateStr(ms);
        System.out.println(date);
    }

    /*
     * 与当前时间相差秒数
     */
    public static String calLastedTime(String str) {
        long a = new Date().getTime();
        Date date = parser(str, YYYY_MM_DDHHMISS);
        long b = 0L;
        if (null != date) {
            b = date.getTime();
        }
        int c = (int) ((a - b) / 1000);
        return String.valueOf(c);
    }

    /*
     * 两时间相差秒数
     */
    public static String calLastedTime(String str, String str2) {
        Date datea = parser(str2, YYYY_MM_DDHHMISS);
        long a = 0L;
        if (null != datea) {
            a = datea.getTime();
        }
        Date dateb = parser(str, YYYY_MM_DDHHMISS);
        long b = 0L;
        if (null != dateb) {
            b = dateb.getTime();
        }
        int c = (int) ((a - b) / 1000);
        return String.valueOf(c);
    }

    //   yyyyMMdd转yyyy-MM-dd
    public static String getNormalDate(String str) {
        try {
            Date format = null;
            format = new SimpleDateFormat("yyyyMMdd").parse(str);
            String longDate = new SimpleDateFormat("yyyy-MM-dd").format(format);
            return longDate;
        } catch (ParseException e) {

            return null;
        }
    }

    //   yyyy-MM-dd转yyyyMMdd
    public static String getYYYYMMDDDate(String str) {
        try {
            Date format = null;
            format = new SimpleDateFormat("yyyy-MM-dd").parse(str);
            String longDate = new SimpleDateFormat("yyyyMMdd").format(format);
            return longDate;
        } catch (ParseException e) {

            return null;
        }
    }


    /**
     * @Method: getDistanceTimes
     * @Param: [str1, str2]
     * @Return: long[]
     * @Description: 判断两个时间相差多少天，多少小时，多少分钟，多少秒 格式:long[天，小时，分钟，秒]
     * @Author: ji.tang
     * @Date: 2022/1/26 15:25
     * @Version: V1.0
     */
    public static long[] getDistanceTimes(String str1, String str2) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date one;
        Date two;
        long day = 0;
        long hour = 0;
        long min = 0;
        long sec = 0;
        try {
            one = df.parse(str1);
            two = df.parse(str2);
            long time1 = one.getTime();
            long time2 = two.getTime();
            long diff;
            if (time1 < time2) {
                diff = time2 - time1;
            } else {
                diff = time1 - time2;
            }
            day = diff / (24 * 60 * 60 * 1000);
            hour = (diff / (60 * 60 * 1000));
            min = ((diff / (60 * 1000)));
            sec = (diff / 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long[] times = {day, hour, min, sec};
        return times;
    }

    /**
     * @Method: subDay <br>
     * @Param: [date] <br>
     * @Return: java.lang.String <br>
     * @Description：传入具体日期 ，返回具体日期减少一天<br>
     * @Author： gc.zuo<br>
     * @Date： 2022/4/1 17:03 <br>
     * @Version： V1.0<br>
     */
    public static String subDay(String date) {
        SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDD);
        Date dt = null;
        try {
            dt = sdf.parse(date);
        } catch (Exception e) {
        }
        Calendar rightNow = Calendar.getInstance();
        rightNow.setTime(dt);
        rightNow.add(Calendar.DAY_OF_MONTH, -1);
        Date dt1 = rightNow.getTime();
        String reStr = sdf.format(dt1);
        return reStr;
    }

    /**
     * 当前日期往前或往后
     * dateString 当前日期
     * dateFormat 日期格式
     * dayCount 移动天数，正数往后推，负数往前推
     */
    public static String dateDelay(String dateString, int dayCount) {
        try {
            Date date = new SimpleDateFormat(YYYYMMDD).parse(dateString);
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            //把日期往后增加一天，正数往后推，负数往前移动
            calendar.add(Calendar.DATE, dayCount);
            //这个时间就是日期改变后的结果
            date = calendar.getTime();
            return new SimpleDateFormat(YYYYMMDD).format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 判断字符串是否为合法的日期格式
     *
     * @param dateStr 待判断的字符串
     * @return
     */
    public static boolean isValidDate(String dateStr) {
        //判断结果 默认为true
        boolean judgeresult = true;
        //1、首先使用SimpleDateFormat初步进行判断，过滤掉注入 yyyy-01-32 或yyyy-00-0x等格式
        //此处可根据实际需求进行调整，如需判断yyyy/MM/dd格式将参数改掉即可
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            //增加强判断条件，否则 诸如2022-02-29也可判断出去
            format.setLenient(false);
            Date date = format.parse(dateStr);
            System.out.println(date);
        } catch (Exception e) {
            judgeresult = false;
        }
        //由于上述方法只能验证正常的日期格式，像诸如 0001-01-01、11-01-01，10001-01-01等无法校验，此处再添加校验年费是否合法
        String yearStr = dateStr.split("-")[0];
        if (yearStr.startsWith("0") || yearStr.length() != 4) {
            judgeresult = false;
        }
        return judgeresult;
    }

    /**
     * @Method: getDateYYYYmmddhhMMss
     * @Param: [time]
     * @Return: java.util.Date
     * @Description: 获取 YYYY-MM-DD HH:mm:ss 格式的日期
     * @Author: ji.tang
     * @Date: 2022/7/7 13:55
     * @Version: V1.0
     */
    public static Date getDateYYYYmmddhhMMss(String time) {
        SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DDHHMISS);
        Date date = new Date();
        try {
            date = sdf.parse(time);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * @Method: isBetween
     * @Param: [date, begin, end]
     * @Return: boolean
     * @Description: 判断日期是否在指定时间范围之内,日期格式均为YYYY-MM-DD
     * @Author: ji.tang
     * @Date: 2022/11/21 20:01
     * @Version: V1.0
     */
    public static boolean isBetween(String begin,String end){
        DateTime dateTime = cn.hutool.core.date.DateUtil.parse(getNormalDate(new Date()),"yyyy-MM-dd");
        DateTime beginTime = cn.hutool.core.date.DateUtil.parse(begin,"yyyy-MM-dd");
        DateTime endTime = cn.hutool.core.date.DateUtil.parse(end,"yyyy-MM-dd");
        return new DateTime(dateTime).isIn(beginTime,endTime);
    }

    public static String time2Str(Date date) {
        return date2Str(date, YYYY_MM_DDHHMISS);
    }

    public static String date2Str(Date date, String pattern) {
        if (date == null) {
            return "";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(date);
    }

}
